package com.jebel.framework.classic.event.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.jebel.framework.classic.event.context.RestTemplateConfiguration;
import com.jebel.framework.classic.event.service.ICommonRestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CommonRestServiceImpl implements ICommonRestService {

    private static Logger logger = LoggerFactory.getLogger(CommonRestServiceImpl.class);

    @Autowired
    RestTemplateConfiguration restTemplateConfiguration;
    @Autowired
    Environment environment;

    @Override
    public String getForObject(String url) {
//        logger.info("url:{}", url);
        long begin = System.currentTimeMillis();
        try {
            String resultStr = restTemplateConfiguration.createRestTemplate().getForObject(url, String.class);
//            logger.info("time:{}ms", (System.currentTimeMillis() - begin));
            if (resultStr != null) {
//                logger.info("data:{}", resultStr);
                return resultStr;
            }
        } catch (Exception exception) {
            logger.info("error:{}", exception);
        }
        return null;
    }
}



